package com.itm.lqm.servlets.grade;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.itm.lqm.entity.Grade;
import com.itm.lqm.service.GradeService;

/**
 * Servlet implementation class upadeGrade1
 */
@WebServlet("/upadeGrade1")
public class upadeGrade1 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public upadeGrade1() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取修改页面的请求参数，然后调用业务逻辑层对象，实现最终修改
				request.setCharacterEncoding("UTF-8");
				response.setCharacterEncoding("UTF-8");
				response.setContentType("text/html; charset=UTF-8");

				int gid = Integer.parseInt(request.getParameter("gid"));
				int usualG = Integer.parseInt(request.getParameter("usualG"));
				int finalG = Integer.parseInt(request.getParameter("finalG"));
				int overallG = Integer.parseInt(request.getParameter("overallG"));
				String sname = request.getParameter("sname");
				String cname = request.getParameter("cname");
				String sno = request.getParameter("sno");
				String clas = request.getParameter("clas");

				Grade g = new Grade(gid,usualG, finalG, overallG,sname,cname,sno,clas);
				
				
				
				GradeService gs=new GradeService();
				boolean result=gs.updateGrade(g);
				System.out.println(g);
				System.out.println(result);
				if(result){
					request.getRequestDispatcher("findAllGrade").forward(request, response);
				}else{
					response.sendRedirect("aaaaaaa.jsp");
				}
				
	}

}
